# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>

pkgname=sniffglue
pkgver=0.15.0
pkgrel=1
pkgdesc='Secure multithreaded packet sniffer'
url='https://github.com/kpcyrd/sniffglue'
arch=('loong64' 'x86_64')
license=('GPL3')
depends=('libpcap' 'libseccomp')
makedepends=('cargo' 'scdoc')
backup=('etc/sniffglue.conf')
source=(https://github.com/kpcyrd/${pkgname}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
        https://github.com/kpcyrd/${pkgname}/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.gz.asc
        sniffglue-sysuser.conf
        sniffglue.conf)
sha512sums=('281e6eeda03da5d04cf882d9a282acbc89cfc1857e7d6a3a9ad9167db69e9c747e2c7706f453a023a4070ea8af2eed5004a73d45960b4d9ed32acac233a8a117'
            'SKIP'
            '2595eb4856bc7a59c078255bf2aeeaa44a4f6a69b37cc8982e5d70a8ef14cb29b83b4d191ab3baabfbcf209f3effd232c10ec5baabc6ce52990969526d6fda98'
            '66e6b87e832ba8424334d24e3457a214e60e67c731471098329d0ca54c574518f7856ba780bb6bffde53bdefe2c8f789a242138ae67e2fef3e562fa083b362b1')
b2sums=('3f40fc7cfe1f97b114a841abb898787fd38afdfba9e0addda8fb81ef2370d033f4b88d1a34a6d2ff825ce8f681755cc9df8d94ab5ef6eafbeddb04e1ca1ddc1d'
        'SKIP'
        '69f5ba2cddca6878b776714c5015c1573df31fc4958432291baa4537349e5bdd1ab4307fd1c00bc20484213c118ecfc2ccfab88b942c0311e4d72872bf4eeeda'
        'ad68689ed08e882f734a613300c14ddfb6d84656dec8dbbed818302b0fe69907f7fc76306f49c0bac019acf4dcb46fec984e7194b16a481f7cc4636ca9aaf303')

validpgpkeys=("64B13F7117D6E07D661BBCE0FE763A64F5E54FD6")

prepare() {
  cd ${pkgname}-${pkgver}
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd ${pkgname}-${pkgver}
  cargo build --frozen --release
  make docs
}

check() {
  cd ${pkgname}-${pkgver}
  cargo test --frozen
}

package() {
  cd ${pkgname}-${pkgver}
  install -Dm 755 target/release/${pkgname} -t "${pkgdir}/usr/bin"

  install -d "${pkgdir}/usr/share/bash-completion/completions" \
             "${pkgdir}/usr/share/zsh/site-functions" \
             "${pkgdir}/usr/share/fish/vendor_completions.d"
  "${pkgdir}/usr/bin/sniffglue" --gen-completions bash > "${pkgdir}/usr/share/bash-completion/completions/sniffglue"
  "${pkgdir}/usr/bin/sniffglue" --gen-completions zsh > "${pkgdir}/usr/share/zsh/site-functions/_sniffglue"
  "${pkgdir}/usr/bin/sniffglue" --gen-completions fish > "${pkgdir}/usr/share/fish/vendor_completions.d/sniffglue.fish"

  install -Dm 644 "${srcdir}/sniffglue-sysuser.conf" "${pkgdir}/usr/lib/sysusers.d/sniffglue.conf"
  install -Dm 644 "${srcdir}/sniffglue.conf" -t "${pkgdir}/etc"
  install -Dm 644 docs/sniffglue.1 -t "${pkgdir}/usr/share/man/man1"
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim: ts=2 sw=2 et:
